import {NativeModules} from 'react-native';
import JJUtil from './JJUtil'

import JJAPPConfig from '../resource/file/appConfig/JJAPPConfig.js'
const { LogLevel } = JJAPPConfig;

const JJLog = { 
    debug(message) {
        if (LogLevel <= 0) {
            console.debug(this.localTimeString() + "[d]" + message);
        }

        if (JJAPPConfig.isAppParasitifer()) {
            NativeModules.JJRNBridge.log(message + "", "0")
        }
    },
    info(message) {
        if (LogLevel <= 1) {
            console.info(this.localTimeString() + "[i]" + message);
        }

        if (JJAPPConfig.isAppParasitifer()) {
            NativeModules.JJRNBridge.log(message + "", "1")
        }
    },
    warn(message) {
        if (LogLevel <= 2) {
            console.warn(this.localTimeString() + "[w]" + message);
        }

        if (JJAPPConfig.isAppParasitifer()) {
            NativeModules.JJRNBridge.log(message + "", "2")
        }
    },
    error(message) {
        if (LogLevel <= 3) {
            console.error(this.localTimeString() + "[e]" + message);
        }

        if (JJAPPConfig.isAppParasitifer()) {
            NativeModules.JJRNBridge.log(message + "", "3")
        }
    },
    localTimeString() {
        const time = new Date()
		const localString = time.toLocaleString() + '  '
		return localString
    },
}

export default JJLog;
